import {config} from '@/common/config.js'
import store from "@/store";
let upload = (filePath, type) => {
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: config.api+'/sys/common/upload?biz=weapp',
			header: {
				'X-Access-Token': store.getters.token || '',
			},
			filePath: filePath,
			name: 'file',
			success(res) {
				console.log(res)
				if (res.statusCode == 200 && res.data) {
					let data = JSON.parse(res.data)
					if (!data.message) {
						uni.showToast({
							icon: 'none',
							title: res.msg || '上传失败'
						})
						reject()
						return
					}
					resolve(data.message)
				} else {
					uni.showToast({
						icon: 'none',
						title: res.msg || '上传失败'
					})
					reject()
				}
			},
			file(err) {
				uni.showToast({
					icon: 'none',
					title: '上传失败'
				})
				reject()
			}
		})
	})
}
export default upload